package com.funkyfurrymonkey.world2d;
import box2D.dynamics.B2Body;
import com.funkyfurrymonkey.constants.Convert;

import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.events.EventDispatcher;

/**
 * ...
 * @author Marcos Martinez
 */
class Actor extends EventDispatcher
{

	public var m_cBody:B2Body;
	public var m_cCanvas:Sprite;
	public var m_nRatio:Float; // pixel per meter???
	public function new(cBody:B2Body, cCostume:Bitmap) 
	{
		super();
		m_nRatio = 1;
		m_cBody = cBody;
		m_cCanvas = new Sprite();
		cCostume.x = -cCostume.width / 2;
		cCostume.y = -cCostume.height / 2;
		m_cCanvas.addChild(cCostume);	
		
	}
	
	public function destroy()
	{
		
	}
	
	public function updateNow()
	{
		if(m_cBody.isActive())
			updateMyLook();
		childSpecificUpdate();
	}
	
	public function childSpecificUpdate() 
	{
		 // this is just for extends
	}
	
	public function hits(cData:Dynamic)
	{
		// this is just for extends
	}
	
	private function updateMyLook() 
	{
	
		m_cCanvas.x = m_cBody.getPosition().x*m_nRatio;
		m_cCanvas.y = m_cBody.getPosition().y * m_nRatio;
		m_cCanvas.rotation = m_cBody.getAngle() * Convert.RADIANS_TO_DEGREES;
	}
	
}